package com.es.commons.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述:
 * Old-AgeCareSystem-
 *
 * @author Derek
 * @create 2021-12-09 9:29
 */
@Configuration
public class RabbitMQConfigurer {

    /**
     * @return 创建一个队列
     */
    @Bean
    public Queue queue(){
        Queue queue = new Queue("boot-queue");
        return queue;
    }

    @Bean
    public Queue exQueue1(){
        Queue queue = new Queue("boot-exchange-queue-1");
        return queue;
    }

    @Bean
    public Queue exQueue2(){
        Queue queue = new Queue("boot-exchange-queue-2");
        return queue;
    }

    /**
     * @return 交换机
     */
    @Bean
    public DirectExchange bootExchange(){
        DirectExchange exchange = new DirectExchange("boot-exchange");
        return exchange;
    }

    @Bean
    public Binding bingingQueue1ToExchange(){
       return BindingBuilder.bind(exQueue1()).to(bootExchange()).with("boot-queue-binding-key-1");
    }

    @Bean
    public Binding bingingQueue2ToExchange(){
        //绑定要给队列到交换机上，指定了 routing-key
        return BindingBuilder.bind(exQueue2()).to(bootExchange()).with("boot-queue-binding-key-2");
    }


    @Bean
    public Queue smsQueue(){
        Queue queue = new Queue("sms-queue");
        return queue;
    }
    /**
     * @return 短信交换机
     */
    @Bean
    public DirectExchange smsExchange(){
        DirectExchange exchange = new DirectExchange("sms-exchange");
        return exchange;
    }

    @Bean
    public Binding smsBinding(){
        //绑定要给队列到交换机上，指定了 routing-key
        return BindingBuilder.bind(smsQueue()).to(smsExchange()).with("sms-q-ex-key");
    }

}
